package org.example.remote;

import feign.*;
import org.example.common.UserContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class FeignConfig {
    //重试机制
    @Bean
    public Retryer retryer(){
        return new Retryer.Default(100, 1000, 3);
    }
    //携带登录信息
    //定义一个 Feign 框架下的请求拦截器：
    @Bean
    public RequestInterceptor requestInterceptor() {
        return template -> {
            template.header("username", UserContext.getUsername());
            template.header("userId", UserContext.getUserId());
            template.header("realName", UserContext.getRealName());
        };
    }

//    @Bean
//    public Feign.Builder feignBuilder() {
//        return Feign.builder()
//                .contract(new Contract.Default())
//                .logger(new Logger.ErrorLogger())
//                .retryer(new Retryer.Default(100, 1000, 3))
//                .options(new Request.Options(5000, 10000));
//    }
}